// This file is part of MinIO Console Server
// Copyright (c) 2020 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

export interface Usage {
  usage: number;
  buckets: number;
  objects: number;
}
export const ChartUrl = "http://192.168.0.254:9090/api/v1/query_range?query=";
export const AllQueryUrl = "http://192.168.0.254:9090/api/v1/label/__name__/values";
export const AlertsUrl = "http://192.168.0.254:9090/alerts";

export const timeConvert = (timestamp:any) => {
  timestamp = timestamp+'';
  timestamp = timestamp.length==10?timestamp*1000:timestamp;
  var date = new Date(timestamp);
  var y = date.getFullYear();  
  var m = (date.getMonth() + 1).toString();  
  m = parseInt(m) < 10 ? ('0' + m) : m;  
  var d = date.getDate().toString();  
  d = parseInt(d) < 10 ? ('0' + d) : d;  
  var h = date.getHours().toString();
  h = parseInt(h) < 10 ? ('0' + h) : h;
  var minute = date.getMinutes().toString();
  var second = date.getSeconds().toString();
  minute = parseInt(minute) < 10 ? ('0' + minute) : minute;  
  second = parseInt(second) < 10 ? ('0' + second) : second; 
  return y + '-' + m + '-' + d +' '+ h +':'+ minute +':' + second;
}
export const setFormat = (x:any) =>{
  if (x < 10) {
    x = "0" + x;
  }
  return x;
 }
 export const beforeNowtimeByMinu = (beforetime:any) => {
    var date = new Date(); //日期对象
    date.setMinutes (date.getMinutes () - beforetime);
    var now = "";
    now = date.getFullYear()+"-"; //读英文就行了
    now = now + (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';//取月的时候取的是当前月-1如果想取当前月+1就可以了
    now = now + setFormat(date.getDate())+" ";
    now = now + setFormat(date.getHours())+":";
    now = now + setFormat(date.getMinutes())+":";
    now = now + setFormat(date.getSeconds())+"";
    return now;
}